/**
 *  JSimProd - Java simulation code for production processes
 *  Copyleft Jorge Mira Yagüe <jorge.mira.yague@gmail.com>
 *  Universidad de Alicante 2009
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package lib.model.distribution;

/**
 * This class defines an normal distribution, where the value is returned
 * following a gaussian function. More info on
 * <a href="http://en.wikipedia.org/wiki/Normal_distribution">
 * Wikipedia</a>
 * @see Distribution
 * @author Jorge Mira Yagüe
 */
public class NormalDistribution extends Distribution {

    /**
     * Builds an empty normal distribution
     */
    public NormalDistribution() {
        super(DistributionType.NORMAL, 0, 0);
    }

    /**
     * Builds a normal distribution with the mean and the variance given
     * @param mean the mean of the distribution
     * @param variance the variance of the distribution
     */
    public NormalDistribution(double mean, double variance) {
        super(DistributionType.NORMAL, mean, variance);
    }

    /**
     * Returns the value of the distribution using the mean and the variance
     * given
     * @return the static value of the distribution
     */
    @Override
    public double getResult() {
        double xi;
        double result;
        do {
            xi = random.nextGaussian();
        } while (xi <= 0);
        result = (xi * variance) + mean;
        return result;
    }
}
